package com.polytech.diploma.OracleStatStep;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.Result;
import org.pentaho.di.core.database.Database;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleDatabaseException;
import org.pentaho.di.core.exception.KettleException;

public class Test {

	/**
	 * @param args
	 * @throws KettleException 
	 */
	public static void main(String[] args) throws KettleException {
		// TODO Auto-generated method stub

		KettleEnvironment.init();

		DatabaseMeta dbmeta = new DatabaseMeta();
		dbmeta.setName("OracleConn");
		dbmeta.setDatabaseType("Oracle");
		dbmeta.setAccessType(0);
		dbmeta.setHostname("192.168.119.1");
		dbmeta.setDBName("XE");
		dbmeta.setDBPort("1521");
		dbmeta.setUsername("system");
		dbmeta.setPassword("111");
		
		Database db = new Database(null, dbmeta);
		String query = "SELECT owner, table_name FROM dba_tables WHERE owner='HR'";
		String result = "";
		try {
			db.connect();
			PreparedStatement pstmt = db.prepareSQL(query);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
			    result+=rs.getString("table_name")+"\n";
			}
			System.out.println(result);
			db.disconnect();
		} catch (KettleDatabaseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
